!!!---->>>  Requires a lot of RAM <<<----!!!

Read for understanding:
https://doi.org/10.1038/s41598-025-85982-4
https://doi.org/10.1016/j.ultramic.2024.114101
https://doi.org/10.1007/s11075-024-01759-2
https://doi.org/10.1016/j.ultramic.2025.114159

Fast Guide:

(Required)
-> Load: Select EEELS map ".dm4"-File or the saved ".mat" file from this program
-----------------------------------
(Optional)
-> Load 2D Gain Ref: if availlable (stored in Gatan Folder of the microscope's computer)
-> Load 2D ZLP: capture 2D representation of ZLP in Micrograph
	-> Correct Saturation: Linearizes the gain throughout the dynamic range of the detector
-> HQDark/Dark/None swth between different Background subtractions
-> Remove DF Artifacts: remove cosmic rays in DarkFrame Background data, remove ZLP ghost in DarkFrame Background data

------------------------------------
(Required)
-> Broad Align ZLP: Energy Align ZLPs with respect to position of max. intensity. Draw window to fit the ZLPs

------------------------------------
(Optional)
-> Fine Align ZLP: Use cross-correlation and gaussian fit to align ZLPs. Draw window to fit the ZLPs
-> Remove Artifacts: Removes cosmic rays from EELS data by checking if value is outside a Threshold value of the neighboring data points. 

------------------------------------
(Required)
-> Select Background: Select substrate or region without structure of interest. Select region before the ZLP begins.
	-> if necessary upload detector PSF. Scripts to determine noise parameters and the detector PSF are found here 
	  Christian Zietlow (2025). Noise evaluation in transmission electron microscopy (TEM) (https://de.mathworks.com/matlabcentral/fileexchange/180009-noise-evaluation-in-transmission-electron-microscopy-tem)

------------------------------------
(Optional)
-> update noise paramters accordingly
-> "Signal Gain Value" is conversion gain from beam electrons to digital Counts
-> "Beam Current Dev" is beam current deviation of the electron gun
-> "Smothing factors" are noise smoothing due to convolution with the detector PSF
-> "Detector Noise Std" gives the Gaussian read out noise of the EELS channels (Channel) and of all channels summed (Full)
-> "Drift Corr" determines the mean drift of the ZLPs in channels
(example values provided in "NoiseParams.para")

-----------------------------------
(Required)
-> LoadZLP: Load Vacuum ZLP file (optimally 15x15 STEM-EELS map or larger), corrections as Above
-> AlignZL to Data: shift the Vacuum ZLP 0-position to the 0-position of the EELS data.
-> FitZLP: Select fit Region, optinally remove residuals of ZLP (otherwise just press cancel window with x)

(Settings in Live Fit Panel: Display Options: Subtracts ZLP from EELS data Sum all (Displays average ZLP-EELS data difference as spectrum) | Sum Line (ZLP-EELS data difference averaged for EELS map row in x direcion) | Pixelwise (each spec individually)
Diff. Mult: Scaling Factor for displaying the differences between ZLP and EELS data
Width: zoom in or zoom out in width)

--->> 3D Deconv ZLP with 150 iterations (500 for convergence) 
     -> DevonvSub: deconvolves the Substrate characteristics out of the spectrum
-> Denoise Beam denoises the Intensity map

---------------------------------------------------------------------------

-> Intensity Map: Shows the sum of all EELS channels as a 2D map (total intensity of the spectrum)
-> FWHM map: Shows the FWHM of the ZLP of all spectra as a 2D map
-> ZLP Drift map: Shows the Drift of the ZLP with respect to the 0-position

-> Show Original: Shows undeconvolved data
-> Show Devonv: Show deconvolved data

-> Select single spectra gives the spectrum of the selected position 
-> Select Spectra allows to draw a rectagle to average several spectra of the rectangle Region
(both allow shwithing between Show Original and Deconv)


----------------------------------------------------------------------------
Norm: allows swithing between normalized EELS data and EELS data as acquired
Contours: Show the structures boundaries (adjustable with Thres value)
Remove ZLP: Shows the EELS data with or without ZLP subtracted

----------------------------------------------------------------------------
Save Session: saves current data to ".mat" file for later load as explained above
Save Img: saves current EELS slice

